#include "terrainPlants.h"


TerrainPlants::TerrainPlants(ID3D10Device * device, int size)
{
	m_d3dDevice=device;
	m_size =size;
}
TerrainPlants::~TerrainPlants()
{
	if(m_d3dDevice!=NULL)
		m_d3dDevice->Release();
	if(m_DrawableObject!=NULL)
		delete(m_DrawableObject);

}

void TerrainPlants::Generate(Terrain *terrain, D3DXVECTOR2 upperLeft, D3DXVECTOR2 lowerRight)
{
	float dx=lowerRight.x-upperLeft.x;
	float dy=upperLeft.y-lowerRight.y;

	SimpleVertex * vertices=new SimpleVertex[m_size];
	DWORD *			indices=new DWORD[m_size];

	for(int i=0; i<m_size; i++)
	{
		indices[i]=i;

		
		float x= (float)(rand()%100)/100;
		float y= (float)(rand()%100)/100;
		x=upperLeft.x+x*dx;
		y=upperLeft.y-y*dy;

		D3DXVECTOR3 pos=D3DXVECTOR3(x,terrain->GetHeight(x,y),y);
		vertices[i].Pos=pos;
		vertices[i].Nor=D3DXVECTOR3(0,1,0);
			

	}

	m_DrawableObject=new DrawableObject(m_d3dDevice);
	m_DrawableObject->CreateIndexBuffer(indices,m_size, D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
	m_DrawableObject->CreateVertexBuffer(vertices, m_size);



}


DrawableObject * TerrainPlants::GetDrawableObject()
{
	return m_DrawableObject;
}


